<!DOCTYPE html>

<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<html lang="en">
<head>
    <meta charset="utf-8">
    <meta http-equiv="x-ua-compatible" content="ie=edge">
    <title>Dashboard V.1 | Kiaalap - Kiaalap Admin Template</title>
    <meta name="description" content="">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- favicon
		============================================ -->
    <link rel="shortcut icon" type="image/x-icon" href="img/favicon.ico">
    <!-- Google Fonts
		============================================ -->
    <link href="https://fonts.googleapis.com/css?family=Roboto:100,300,400,700,900" rel="stylesheet">
    <!-- Bootstrap CSS
		============================================ -->
    <link rel="stylesheet" href="css/bootstrap.min.css">

    <!-- Lobibox CSS
        ============================================ -->
    <link rel="stylesheet" href="css/notifications/Lobibox.min.css">

    <!-- Bootstrap CSS
		============================================ -->
    <link rel="stylesheet" href="css/font-awesome.min.css">


    <link rel="stylesheet" href="css/mloading.css">

    <!-- DatetimePicker CSS
        ============================================ -->
    <link rel="stylesheet" href="css/bootstrap-datetimepicker.min.css">

    <!-- owl.carousel CSS
		============================================ -->
    <link rel="stylesheet" href="css/owl.carousel.css">
    <link rel="stylesheet" href="css/owl.theme.css">
    <link rel="stylesheet" href="css/owl.transitions.css">
    <!-- animate CSS
		============================================ -->
    <link rel="stylesheet" href="css/animate.css">
    <!-- normalize CSS
		============================================ -->
    <link rel="stylesheet" href="css/normalize.css">
    <!-- meanmenu icon CSS
		============================================ -->
    <link rel="stylesheet" href="css/meanmenu.min.css">
    <!-- main CSS
		============================================ -->
    <link rel="stylesheet" href="css/main.css">
    <!-- educate icon CSS
		============================================ -->
    <link rel="stylesheet" href="css/educate-custon-icon.css">
    <!-- morrisjs CSS
		============================================ -->
    <link rel="stylesheet" href="css/morrisjs/morris.css">
    <!-- mCustomScrollbar CSS
		============================================ -->
    <link rel="stylesheet" href="css/scrollbar/jquery.mCustomScrollbar.min.css">
    <!-- metisMenu CSS
		============================================ -->
    <link rel="stylesheet" href="css/metisMenu/metisMenu.min.css">
    <link rel="stylesheet" href="css/metisMenu/metisMenu-vertical.css">
    <!-- calendar CSS
		============================================ -->
    <link rel="stylesheet" href="css/calendar/fullcalendar.min.css">
    <link rel="stylesheet" href="css/calendar/fullcalendar.print.min.css">

    <!-- form CSS
		============================================ -->
    <link rel="stylesheet" href="css/form/all-type-forms.css">

    <!-- style CSS
		============================================ -->
    <link rel="stylesheet" href="css/style.css">
    <!-- responsive CSS
		============================================ -->
    <link rel="stylesheet" href="css/responsive.css">
    <!-- modernizr JS
		============================================ -->
    <script src="//cdn.tiny.cloud/1/ffe1r0324npavc2zd8nptf1ajrdm6jp1gohamktptefohr07/tinymce/5/tinymce.min.js"></script>

    <script src="js/vendor/modernizr-2.8.3.min.js"></script>
    <script src="js/vendor/jquery-1.12.4.min.js"></script>
    <script src="js/mloading.js"></script>
</head>
<body>
<!-- http://tinymce.ax-z.cn/configure/content-appearance.php -->
<input  class="form-control" type="text" id="title" placeholder="标题">
<form method="post" onsubmit="javascript: return false;">
    <textarea id="mytextarea" name="mytextarea"></textarea>
</form>
<input style="display: none" id="fileName">
<button class="btn btn-default" ><a href="historyMsg.jsp">返回</a></button>
<button class="btn btn-success"  id="update" style="display: none" onclick="insert()" ><a href="historyMsg.jsp">发布新消息</a></button>
<button class="btn btn-info" id="save" onclick="upload()">保存文本信息</button>

</body>

<script>
    tinymce.init({
        selector: '#mytextarea',
        resize: true,    // 不允许改变尺寸
        menubar: false,   // 影藏头顶的File、Edit、View等信息
        plugins: "image", //使用图片插件
        toolbar: "undo redo blockquote | formatselect | bold italic | alignleft aligncenter alignright | image", //工具条显示图片按钮
        branding: false,  //显示商标
        // tinymec在文件上传的时候，var formData = new FormData();  formData.append("file")
        images_upload_url: 'http://localhost:8080/tinymce/upload',
        file_picker_types: 'image media'
    });


    function getValue() {
        // 取值的方式
        console.log(tinyMCE.editors[0].getContent())
    }
    function insert() {
        var notifyData = {
            uId:28,
            nTitle:$("#title").val(),
            nPath:$('#fileName').val(),
        };
        /*   $.post('http://localhost:8080/notify/insertNotify',{notifyData},
               function (_data) {
               if (_data.code >0){
                   alert("成功");
               }
           })*/
        $.ajax({
            url:'http://localhost:8080/notify/insertNotify',
            type:'POST',
            dataType:'json',
            data:notifyData,
            success:function (_data) {
                if(_data.code>0){
                    $("#update").attr("style","display:none");
                    $("#save").attr("style","display:block");
                    alert("提交成功！");
                }
            }
        })
    }
    function upload() {
        var words = tinyMCE.editors[0].getContent();
        $.ajax({
            url:'http://localhost:8080/notify/upload',
            type:'POST',
            dataType: 'json',
            data:{
                words:encodeURI(encodeURI(words)),
            },
            success:function (_data) {
                if (_data.code>0){
                    $('#fileName').val(_data.fileName);
                    $("#update").attr("style","display:block");
                    $("#save").attr("style","display:none");
                    alert('保存成功，下一步进行提交');
                }
            }
        })
    }

</script>
</html>